package com.liyong.bos.service;

import com.liyong.bos.dao.BcStaffMapper;
import com.liyong.bos.domain.BcStaff;
import com.liyong.bos.domain.BcStaffExample;
import com.liyong.bos.utils.UUIDUtil;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by ApacheMoy on 2017/4/8.
 */
@Service
public class GetStaffServiceImpl implements GetStaffService {
    @Autowired
    private BcStaffMapper bcStaffMapper;
    public List<BcStaff> findAllBcStaff(String userNameSearch, int start, int pageSize) {
        BcStaffExample bcStaffExample=new BcStaffExample();
        bcStaffExample.setLimitStart((start-1)*pageSize);
        bcStaffExample.setOrderByClause("id asc");
        bcStaffExample.setLimitEnd(pageSize);
        if(StringUtils.isNotBlank(userNameSearch)){
            bcStaffExample.or().andNameLike(userNameSearch);
        }
        List<BcStaff> users=bcStaffMapper.selectByExample(bcStaffExample);
        if(users.size()>0){
            return users;
        }else
            return null;
    }

    /**
     **根据姓名和手机号查询
     * 若查询全部，请将参数设置成null
     * 没有根据id查询的选项（32位没有查询选项）
     * */
    public int countByPage(String name,String phone){
        BcStaffExample bcStaffExample=new BcStaffExample();
        if(StringUtils.isNotBlank(name)){
            bcStaffExample.or().andNameLike(name);
        }
        if(StringUtils.isNotBlank(phone)){
            bcStaffExample.or().andTelephoneLike(phone);
        }
        return bcStaffMapper.countByExample(bcStaffExample);
    }
    /**
     * 暂时不做uuid检验
     * */
    public int insertBcStaff(BcStaff bcStaff){
        String uuid=UUIDUtil.getUUID();
        bcStaff.setId(uuid);
        return bcStaffMapper.insertSelective(bcStaff);
    }

    /**
     * 更新
     * */
    public int updateBcStaff(BcStaff bcStaff){
        /**
         * 根据主键更新
        * */
        return bcStaffMapper.updateByPrimaryKeySelective(bcStaff);
    }
    /**
     * 删除
     * */
    public int deleteBcStaffs(String bcStaffId){
        /**
         * 根据主键删除
         * */
        return bcStaffMapper.deleteByPrimaryKey(bcStaffId);
    }

}
